package com.lizard.schedule.ui.fragment.base;

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lizard.schedule.log.ScheduleLog;

/**
 * 项目中所有Fragment继承自本类
 */
public class BaseFragment extends Fragment {

    private final String TAG = getClass().getSimpleName();

    private final String TAG_LIFE = TAG + " life";

    /**
     * activity 生命周期log是否打印
     */
    private final boolean mLiftLogAble = false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        logLife("onCreate(Bundle savedInstanceState)");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        logLife("onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)");
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        logLife("onViewCreated(View view, Bundle savedInstanceState)");
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        logLife("onActivityCreated(Bundle savedInstanceState)");
    }

    @Override
    public void onStart() {
        super.onStart();
        logLife("onStart()");
    }

    @Override
    public void onResume() {
        super.onResume();
        logLife("onResume()");
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        logLife("onSaveInstanceState(Bundle outState)");
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        logLife("onConfigurationChanged(Configuration newConfig)");
    }

    @Override
    public void onPause() {
        super.onPause();
        logLife("onPause()");
    }

    @Override
    public void onStop() {
        super.onStop();
        logLife("onStop()");
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        logLife("onLowMemory()");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        logLife("onDestroyView()");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        logLife("onDestroy()");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        logLife("onDetach()");
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        logLife("onAttach(Activity activity)");
    }

    /**
     * 生命周期log输出
     */
    private void logLife(String actLife){
        if(mLiftLogAble){
            ScheduleLog.v(TAG_LIFE, actLife);
        }
    }
}
